package com.joysuch.wwyt.bp.controller;


import com.joysuch.wwyt.bp.bean.inspect.BpInspectTypeBean;
import com.joysuch.wwyt.bp.entity.inspect.BpInspectType;
import com.joysuch.wwyt.bp.service.BpInspectTypeService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/bp/inspect-type")
@Api(tags = "巡检-检查计划管理-检查类型")
@CrossOrigin
public class BpInspectTypeController {

    @Autowired
    private BpInspectTypeService bpInspectTypeService;

    @GetMapping("/list")
    @ApiOperation(value = "检查类型列表", response = List.class)
    public ResultBean list(Pageable pageable) {
        return bpInspectTypeService.list(pageable);
    }

    @PostMapping("/save")
    @RequiresPermissions("bp:inspect-type:save")
    @ApiOperation(value = "保存检查类型", response = BpInspectType.class)
    public ResultBean save(@RequestBody @Valid BpInspectTypeBean bean) {
        return bpInspectTypeService.save(bean);
    }

    @GetMapping("/delete/{id}")
    @RequiresPermissions("bp:inspect-type:delete")
    @ApiOperation(value = "根据检查类型ID删除")
    @ApiImplicitParam(name = "id", value = "检出类型ID", paramType = "path", required = true)
    public ResultBean delete(@PathVariable Long id) {
        bpInspectTypeService.deleteById(id);
        return ResultBean.defaultSuccessResult();
    }

}
